<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<jsp:include page="/WEB-INF/common/head.jsp" flush="true" />
<table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
       
        <div style="text-align: left; margin:6px;">
        
          	<a href="#" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" id="btn-add"  plain="true" onclick="add()">增加</a>
            <a href="#" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" id="btn-edit" plain="true" onclick="update()" >编辑</a>
            <a href="#" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"  id="btn-unvisible" plain="true" onclick="del()">删除</a>
            <a href="#" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"  id="btn-unvisible" plain="true" onclick="grant()">权限授权</a>
            <a href="#" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"  id="btn-unvisible" plain="true" onclick="obj_grant()">对象授权</a>
        </div>
    </div>
<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
        rownumbers:true,
    	url:'${context_path}/sys/role/getListData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        
        columns: [[
		          {field:'id', title: 'id',checkbox:true}
	           	 ,{field:'name', title: '角色名称', width:120, sortable: true}
	           	 ,{field:'des', title: '描述', width:120, sortable: true}
	           ]]
	};
$(function() {
	//handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();

function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("角色管理-增加", '${context_path}/sys/role/add', {size: '600x400'});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("角色管理-编辑", '${context_path}/sys/role/add?id=' + id, {size: '600x400'});
}

function grant() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("角色管理-权限授权",'${context_path}/sys/role/getZtree?roleId='+id+'&type=1', {size: '600x400'});
}

function obj_grant() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("角色管理-对象授权", '${context_path}/sys/objGroup/getAllTree?roleId='+id, {size: '600x400'});
}


function del() {
	var ids = "";
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids = ids+item.id+",";
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据！");
		return;
	}
	confirmMsg("确认删除？", function() {
		$.post("${context_path}/sys/role/setVisible", {"ids": ids}, function(data) {
			
			if (data.code == 0) {
				showMsg("删除成功！");
				datagrid.datagrid("reload");
			}  else{
				showMsg(data.msg);
			} 
		});
	});
}



//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
</script>
  <jsp:include page="/WEB-INF/common/dialogWindow.jsp" flush="true" />
   <jsp:include page="/WEB-INF/common/foot.jsp" flush="true" />